$(function(){
	
	
	var parm = $("#tabContent > .tab-pane.active").data();
	paramTabPage[tabId] = parm.param;
	var type1 = parm.type1;
	
	var thead='<table id="caseListTable-sub" class="table display nowrap" style="width:100%;"></table>';
	$("#"+tabId+" #caseListTable").html(thead);
	
	var caseData = parm.data;
	if(caseData && caseData.length>=0){
		if( caseData.length == 0 ) {
			
		}
		var columns=[
	                   {
	                	   "data": "MRNO","title":"病案号",
	                	   "render": function(obj, type, full){
								var mrNo = full.MRNO;
							return "<a href=\"javascript:medicalRecord('"+full.ID+"','"+full.PATIENTNAME+"')\">"+mrNo+"</a>";
						}
	                   },
	                   { "data": "IP_COUNT",title:"住院次数" },
	                   { "data": "PATIENTNAME","title":"姓名" },
	                   {
	                	   "data": "SEX","title":"性别",
	                	   "render": function(obj, type, full) {
				               var sex=full.SEX;
				               if(sex == "1"){
				              	 sex = "男";
				               }else if(sex == "2"){
				              	 sex = "女";
				               }else{
				              	 sex = "未知";
				               }
				               return sex;
				           }
	                   },
	                   { "data": "AGEYEAR","title":"年龄" },
	                   { "data": "INDATE","title":"入院时间"},
	                   { "data": "OUTDATE","title":"出院时间"},
	                   { "data": "OUTDEP" ,"title":"出院科室"},
	                   { "data": "INDAYS","title":"住院日" },
	                   { 
	                	   "data": "costamount","title":"总费用(元)", "type":"numeric-comma",
	                	   "render": function(obj, type, full){
	                		   var costamount=dealwithFloat(full.COSTAMOUNT);
	                		   return costamount;
	                	   } 
	                   },
	                   {
	                	   "data": "DRUGCOST","title":"药品费用(元)" , "type":"numeric-comma",
	                	   "render": function(obj, type, full){
	                		   var drugcost=dealwithFloat(full.DRUGCOST);
	                		   return drugcost;
	                	   } 
	                   },
	                   { "data": "DIAGNOSEDESSMAIN","title":"主要诊断","render": function(obj, type, full) {
		  	            	 return linefeedText(obj,25);
		  	             	}
		                   },
		               { "data": "OTHERDIAG","title":"其他诊断","render": function(obj, type, full) {
			  	            	 return linefeedText(obj);
			  	            }
			               },
	                   { "data": "OPERATION","title":"手术操作","render": function(obj, type, full) {
	  	            	 return linefeedText(obj);
	  	             	} 
	                   },
	                   { "data": "DRGCODE","title":"DRG代码" },
	                   { "data": "DRG","title":"DRG描述","render": function(obj, type, full) {
	  	            	 return linefeedText(obj);
	  	             	}
	                   },
	                   { "data": "WEIGHT","title":"病组权重" },
	                   { "data": "AVGDAYSSTD" ,"title":"平均住院日(病组标杆值)"},
	                   { 
	                	   "data": "avgFeeStd" ,"title":"次均费用(元)(病组标杆值)", "type":"numeric-comma",
	                	   "render":  function(obj, type, full){
	                		   var avgFeeStd=dealwithFloat(full.AVGFEESTD);
	                		   return avgFeeStd;
	                	   } 
	                		   
	                   }];
		var paramsDataTables={pageLength:50,scrollX:true,scrollY:'350px',lengthMenu:[[ 50,100,500, 1000,99999],[ 50,100,500, 1000,'全部']],columnDefs:[{"orderable": true,"targets": [ 0,4,5,7,8,14 ] },{"orderable": false,"targets": '_all'}]};
		var oTable=$("#"+tabId+" #caseListTable-sub").dataTableBasic(columns,caseData,paramsDataTables);
		$('#'+tabId+' #'+"caseListTable-sub_wrapper .dataTables_scrollBody table tbody").attr('id','table');//tbody加上ID，病案号的样式
	    $('#'+tabId+' #'+"caseListTable-sub_wrapper .dataTables_scrollHeadInner table thead th").css({'text-align':'center'});
		oTable.columns.adjust();//tbody加了样式，重新调整宽度
	}else{
		var param=drgUI.setAjaxData(tabId);
		param.type1=type1;
		$.post(contextPath+'/CaseAnalysis/caseData.dhc', param).done(function(result){
				var data = result.data;
				var columns=[
			                   {
			                	   "data": "MRNO","title":"病案号",
			                	   "render": function(obj, type, full){
										var mrNo = full.MRNO;
									return "<a href=\"javascript:medicalRecord('"+full.ID+"','"+full.PATIENTNAME+"')\">"+mrNo+"</a>";
								}
			                   },
			                   { "data": "PATIENTNAME","title":"姓名" },
			                   {
			                	   "data": "SEX","title":"性别",
			                	   "render": function(obj, type, full) {
						               var sex=full.sex;
						               if(sex == "1"){
						              	 sex = "男";
						               }else if(sex == "2"){
						              	 sex = "女";
						               }else{
						              	 sex = "未知";
						               }
						               return sex;
						           }
			                   },
			                   { "data": "AGEYEAR","title":"年龄" },
			                   { "data": "INDATE","title":"入院时间"},
			                   { "data": "OUTDATE","title":"出院时间"},
			                   { "data": "OUTDEP","title":"出院科室" },
			                   { "data": "INDAYS" ,"title":"住院日"},
			                   { 
			                	   "data": "costamount","title":"总费用(元)", "type":"numeric-comma",
			                	   "render": function(obj, type, full){
			                		   var costamount=dealwithFloat(full.COSTAMOUNT);
			                		   return costamount;
			                	   } 
			                   },
			                   {
			                	   "data": "DRUGCOST","title":"药品费用(元)" , "type":"numeric-comma",
			                	   "render": function(obj, type, full){
			                		   var drugcost=dealwithFloat(full.DRUGCOST);
			                		   return drugcost;
			                	   } 
			                   },
			                   { "data": "DIAGNOSEDESSMAIN","title":"主要诊断","render": function(obj, type, full) {
			  	            	 return linefeedText(obj);
			  	             	}
			                   },
			                   { "data": "OTHERDIAG","title":"其他诊断","render": function(obj, type, full) {
				  	            	 return linefeedText(obj);
				  	             	}
				                   },
			                   { "data": "OPERATION","title":"手术操作","render": function(obj, type, full) {
			  	            	 return linefeedText(obj);
			  	             	}
			                   },
			                   { "data": "DRGCODE","title":"DRG代码" },
			                   { "data": "DRG","title":"DRG描述","render": function(obj, type, full) {
			  	            	 return linefeedText(obj);
			  	             	}
			                   },
			                   { "data": "WEIGHT" ,"title":"病组权重"},
			                   { "data": "AVGDAYSSTD","title":"平均住院日(病组标杆值)" },
			                   { 
			                	   "data": "avgFeeStd","title":"平均费用(元)(病组标杆值)" , "type":"numeric-comma",
			                	   "render":  function(obj, type, full){
			                		   var avgFeeStd=dealwithFloat(full.AVGFEESTD);
			                		   return avgFeeStd;
			                	   } 
			                		   
			                   }];
				var paramsDataTables={pageLength:50,scrollX:true,scrollY:'350px',lengthMenu:[[ 50,100,500, 1000,99999],[ 50,100,500, 1000,'全部']],columnDefs:[{"orderable": false,"targets": [ 0 ] }]};
				var oTable=$("#"+tabId+" #caseListTable-sub").dataTableBasic(columns,data,paramsDataTables);
				$('#'+tabId+' #'+"caseListTable-sub_wrapper .dataTables_scrollBody table tbody").attr('id','table');//tbody加上ID，病案号的样式
			    $('#'+tabId+' #'+"caseListTable-sub_wrapper .dataTables_scrollHeadInner table thead th").css({'text-align':'center'});
				oTable.columns.adjust().draw();//tbody加了样式，重新调整宽度
			});
	}
});

function dealwithFloat(number){
	if (number!=null&& "" != number) {
		return formatNumber(Number(number).toFixed(2));
	}
	return "";
}
